{ config, lib, ... }:
with lib;
{
  services.dnsmasq = {
    alwaysKeepRunning = mkDefault true;
    resolveLocalQueries = mkDefault true;
    settings = {
      all-servers = mkDefault true;
      bind-dynamic = mkDefault true;
      bogus-priv = mkDefault true;
      cache-size = mkDefault 1500;
      domain = mkIf config.services.avahi.enable
        config.services.avahi.domainName;
      domain-needed = mkDefault true;
      expand-hosts = mkDefault true;
      listen-address = mkDefault "127.0.0.1";
      no-negcache = mkDefault true;
      no-poll = mkDefault true;
      no-resolv = mkDefault true;
      server = builtins.concatLists [
        (optionals config.services.avahi.enable [
          "/${config.services.avahi.domainName}/"
        ]) [
          "8.8.8.8"
          "8.8.4.4"
          "1.1.1.1"
          "1.0.0.1"
        ] (optionals config.services.yggdrasil.enable [
          "/ygg/324:71e:281a:9ed3::53"
          "/meshname/324:71e:281a:9ed3::53"
          "/meship/324:71e:281a:9ed3::53"
          "/lib/324:71e:281a:9ed3::53"
          "/bazar/324:71e:281a:9ed3::53"
          "/emc/324:71e:281a:9ed3::53"
          "/coin/324:71e:281a:9ed3::53"
        ])
      ];
    };
  };
}
